package com.ckm.controller;

import com.ckm.annotation.LogInfo;
import com.ckm.entity.TeacherCourse;
import com.ckm.entity.ResponseResult;
import com.ckm.service.TeacherCourseService;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@LogInfo
@Validated
@RestController
@RequestMapping("teacherCourse")
public class TeacherCourseController {

    @Autowired
    private TeacherCourseService teacherCourseService;

    /**
     * 添加任课
     * @param teacherCourseList 任课信息list
     * @return 成功信息
     */
    @PostMapping("addTeacherCourse")
    public ResponseResult addTeacherCourse(@RequestBody @Valid List<TeacherCourse> teacherCourseList) {
        teacherCourseService.addTeacherCourse(teacherCourseList);
        return new ResponseResult(200,"添加成功",null);
    }

    /**
     * 更新任课
     * @param teacherCourse 更新的信息
     * @return 成功信息
     */
    @PutMapping
    public ResponseResult updateTeacherCourse(@RequestBody TeacherCourse teacherCourse) {
        teacherCourseService.updateTeacherCourse(teacherCourse);
        return new ResponseResult(200,"更新成功","");
    }

    /**
     * 删除任课
     * @param id 任课Id
     * @return 成功信息
     */
    @DeleteMapping
    public ResponseResult deleteTeacherCourse(@RequestParam(name = "id") Integer id) {
        teacherCourseService.deleteTeacherCourse(id);
        return new ResponseResult(200,"删除成功","");
    }

    /**
     * 查找任课信息
     * @param teacherCourse 查找词
     * @param pageNum 页码
     * @param pageSize 页大小
     * @return 分页结果集
     */
    @PostMapping("find")
    public ResponseResult findTeacherCourse(@RequestBody TeacherCourse teacherCourse, @RequestParam(name = "pageNum",defaultValue = "1") int pageNum, @RequestParam(name = "pageSize", defaultValue = "10") int pageSize) {
        return new ResponseResult(200,"查找完毕",teacherCourseService.getTeacherCoursePage(teacherCourse,pageNum,pageSize));
    }

    /**
     * 开放课程选课
     * @param courseNameList 课程名列表
     * @return 成功信息
     */
    @PostMapping("openSelect")
    public ResponseResult openStudentCourse(List<TeacherCourse> courseNameList) {
        teacherCourseService.openChooseCourse(courseNameList);
        return new ResponseResult(200,"开始选课","");
    }
}
